
var MyQueue = function() {
    this.queIn = [];
    this.queOut = [];
};

/** 
 * @param {number} x
 * @return {void}
 */
MyQueue.prototype.push = function(x) {
    this.queIn.push(x);
};

/**
 * @return {number}
 */

// 出栈数组不为空时，先pop出栈数组，保证顺序。
MyQueue.prototype.pop = function() {
    while(this.queOut.length) {
        return this.queOut.pop();
    }
    while(this.queIn.length) {
        this.queOut.push(this.queIn.pop());
    }
    return this.queOut.pop();
};

/**
 * @return {number}
 */
MyQueue.prototype.peek = function() {
    const x = this.pop();
    this.queOut.push(x);
    return x;
};

/**
 * @return {boolean}
 */
MyQueue.prototype.empty = function() {
    return !this.queIn.length&&!this.queOut.length;
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * var obj = new MyQueue()
 * obj.push(x)
 * var param_2 = obj.pop()
 * var param_3 = obj.peek()
 * var param_4 = obj.empty()
 */